/**
 * 通过两个位置的经纬度计算距离,保留小数点后两位
 */
const contDistance = (longitude1, latitude1, longitude2, latitude2) => {
	// var radLat1 = latitude1 * Math.PI / 180.0;
	// var radLat2 = latitude2 * Math.PI / 180.0;
	// var a = radLat1 - radLat2;
	// var b = longitude1 * Math.PI / 180.0 - longitude2 * Math.PI / 180.0;
	// var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(
	// 	Math.sin(b / 2), 2)));
	// s = s * 6378.137;
	// s = Math.round(s * 10000) / 10;
	// return s;

	let PI = 3.14159265358979323; //圆周率
	let R = 6371229; //地球半径

	var lon1 = longitude1;
	var lat1 = latitude1;

	var lon2 = longitude2;
	var lat2 = latitude2;

	let x, y, distance;
	let lonres = lon1 > lon2 ? lon1 - lon2 : lon2 - lon1;
	let latres = lat1 > lat2 ? lat1 - lat2 : lat2 - lat1;
	x = (lonres) * PI * R * Math.cos(((lat1 + lat2) / 2) * PI / 180) / 180;
	y = (lat2 - lat1) * PI * R / 180;
	distance = Math.hypot(x, y);

	// console.log(distance)
	return distance;
}

export default {
	contDistance,
}
